﻿using System;
using System.Runtime.CompilerServices;
using UnityEngine;

internal class GameGUIHelper : Singleton<GameGUIHelper>
{
    private static GUISkin guiSkin;
    private Action onGUI;

    private void Awake()
    {
        guiSkin = GameResources.GUISkin;
    }

    public void Draw(Action guiAction)
    {
        <Draw>c__AnonStorey52 storey = new <Draw>c__AnonStorey52 {
            guiAction = guiAction,
            <>f__this = this
        };
        this.onGUI = (Action) Delegate.Combine(this.onGUI, storey.guiAction);
        this.StartWaitForFrames(2, new Action(storey.<>m__78));
    }

    private void OnGUI()
    {
        GUI.skin = guiSkin;
        GUI.depth = 0;
        if (this.onGUI != null)
        {
            this.onGUI();
        }
    }

    public static void RegisterGUIAction(Action guiAction)
    {
        GameGUIHelper instance = Singleton<GameGUIHelper>.Instance;
        instance.onGUI = (Action) Delegate.Combine(instance.onGUI, guiAction);
    }

    public static void UnregisterGUIAction(Action guiAction)
    {
        if (Singleton<GameGUIHelper>.Instance != null)
        {
            GameGUIHelper instance = Singleton<GameGUIHelper>.Instance;
            instance.onGUI = (Action) Delegate.Remove(instance.onGUI, guiAction);
        }
    }

    [CompilerGenerated]
    private sealed class <Draw>c__AnonStorey52
    {
        internal GameGUIHelper <>f__this;
        internal Action guiAction;

        internal void <>m__78()
        {
            this.<>f__this.onGUI = (Action) Delegate.Remove(this.<>f__this.onGUI, this.guiAction);
        }
    }
}

